package com.lixin.demo.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lixin.demo.entity.Product;
import com.lixin.demo.mapper.ProductMapper;
import com.lixin.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public float getTotalPrice(Long id, int num) {
        Product product = productMapper.getProductById(id);
        return product.getPrice() * num;
    }

    @Override
    public int reduceStock(Long id, int stock) {
        Product product = productMapper.getProductById(id);
        stock = product.getStock() - stock;
        return productMapper.updateProductStock(id, stock);
    }

}
